layui.use(["app", "api"], function () {
    let app = layui.app
    let api = layui.api

    let obj = {
        hot: [],
        note: [],
        blogroll: [{ title: "百度", logo: "/images/baidu.png" }]
    }

    let data = app.proxy(obj)

    /**
     * 挂载
     */
    app.onMount = function () {
        // 热门项目
        api.post(
            "/app/kb_blog/api/project/search",
            {
                page: 1,
                limit: 2,
                order: [
                    { "key": "weight", "value": "desc" },
                    { "key": "created_at", "value": "desc" }
                ]
            }
        ).then(function (res) {
            data.hot = res.data.data
        })

        // 最新笔记
        api.post(
            "/app/kb_blog/api/note/search",
            {
                page: 1,
                limit: 2,
                order: [{ "key": "created_at", "value": "desc" }]
            }
        ).then(function (res) {
            data.note = res.data.data
        })

        // 友情链接
        api.get("/app/kb_blog/api/blogroll/search")
            .then(function (res) {
                data.blogroll = res.data
            })
    }

})
